class FormController < ApplicationController

  before_filter :login_required
  
  
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @form_pages, @forms = paginate :forms, :per_page => 10
  end

  def show_seeker_form
    @form = Form.find(params[:id])
  end 
  
  def show_admin_view            
    @form = Form.find(params[:id])
  end
  
  def show_judge_view
    @form = Form.find(params[:id])
  end
  
  def show_manager_view
    @form = Form.find(params[:id])
  end
  
  def show
    @form = Form.find(params[:id])
  end

  def new
    @form = Form.new
  end

  def create
    @form = Form.new(params[:form])
    @form.owner_id = current_user
    if @form.save
      flash[:notice] = 'Form was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @form = Form.find(params[:id])
  end

  def update
    @form = Form.find(params[:id])
    if @form.update_attributes(params[:form])
      flash[:notice] = 'Form was successfully updated.'
      redirect_to :action => 'show', :id => @form
    else
      render :action => 'edit'
    end
  end

  def destroy   
    if current_user.is_admin? 
      logger.info "#{current_user.display_name} destroyed form_id #{params[:id]}"
      Form.find(params[:id]).destroy
    end
    redirect_to :action => 'list'
  end
end
